package com.lefevre.cms.web.action.links;

import com.lefevre.cms.bean.RequestResult;
import com.lefevre.cms.bean.ResultCode;
import com.lefevre.cms.bean.links.Links;
import com.lefevre.cms.service.links.LinksService;
import com.lefevre.cms.utils.JsonUtils;
import com.lefevre.cms.web.action.fileSystem.FileManage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 友情链接
 *
 * @author Lefevre
 */
@Controller
public class LinksController {

    @Resource
    LinksService linksService;
    @Resource
    FileManage fileManage;

    @ResponseBody
    @RequestMapping("/control/links/list")
    public String list() throws Exception {
        List<Links> linksList = linksService.findAllLinks();
        if (linksList != null && linksList.size() > 0) {
            for (Links links : linksList) {
                links.setImage(fileManage.fileServerAddress() + links.getImage());
            }
        }
        return JsonUtils.toJSONString(new RequestResult(ResultCode.SUCCESS, linksList));
    }
}
